class SwitchBtu extends egret.DisplayObjectContainer {
	private singal = 1;
	private btu;
	private context: any;
	private openFn;
	private closeFn;
	public constructor(context: any, singal: any, openFn = null, closeFn = null) {
		super();
		this.singal = singal;
		this.openFn = openFn;
		this.closeFn = closeFn;
		this.context = context;
		this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
	}
	private onAddToStage(event: egret.Event) {
		this.btu = new eui.Image();
		this.btu.width = 140;
		this.btu.height = 42;
		this.addChild(this.btu);
		this.touchEnabled = true;
		this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.switchState, this);
		if (this.singal) {
			// switch_off
			this.btu.source = "switch_on_png"
		} else {
			this.btu.source = "switch_off_png";
		}
	}
	public getPoint(x: number, y: number): egret.DisplayObjectContainer {
		this.setPosition(x, y);
		return this;
	}
	private setPosition(x: number, y: number): void {
		this.anchorOffsetX = -1 * x;
		this.anchorOffsetY = -1 * y;
	}

	switchState(evt: egret.TouchEvent): void {
		if (this.singal == 1) {
			this.close();
		} else {
			this.open();
		}
		this.context.soundctr.playSound("switch_mp3");
	}
	public open(): void {
		if (this.openFn) {
			this.openFn.call(this.context);
		}
		this.btu.source = "switch_on_png"
		this.singal = 1;
	}
	public close(): void {
		if (this.closeFn) {
			this.closeFn.call(this.context);
		}
		this.btu.source = "switch_off_png"
		this.singal = 0;
	}
}